package org.kadicon.android.network;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import android.util.Log;

public class SocTCPServer implements Runnable {

	public static final String SERVERIP = "127.0.0.1";
	public static final int SERVERPORT = 12346;

	public void run() {
		try {
			Log.i("TCP", "S: Connecting...");

			ServerSocket serverSocket = new ServerSocket(SERVERPORT);

			while (true) {
				Socket client = serverSocket.accept();
				Log.i("TCP", "S: Receiving...");

				try {
					BufferedReader in = new BufferedReader(
							new InputStreamReader(client.getInputStream()));
					String str = in.readLine();

					Log.i("TCP", "S: Received: '" + str + "'");
				} catch (Exception e) {
					Log.i("TCP", "S: Error", e);
				} finally {
					client.close();
					Log.i("TCP", "S: Done.");
				}

			}

		} catch (Exception e) {
			Log.i("TCP", "S: Error", e);
		}
	}
}
